package com.example.demo7pdf.controller;

import com.example.demo7pdf.util.PdfItext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.context.Context;

import javax.servlet.http.HttpServletResponse;

@RestController
public class PdfController {

    @GetMapping("/pdf/generatePdf")
    public void generatePdfController(HttpServletResponse response) {
        //模板内容填充参数
        Context context = new Context();
        context.setVariable("name2", "晨曦话java");
        context.setVariable("name1", "晨曦话三国");
        PdfItext.htmlToPdfExport("/templates/template.html", "/mnt/pdf/", System.currentTimeMillis() + "_temp.pdf", context, response);

    }
}
